package cn.daniel.goods.controller;


import cn.daniel.commonutils.Response;
import cn.daniel.goods.entity.GoodsSort;
import cn.daniel.goods.service.GoodsSortService;
import cn.daniel.goods.vo.adminVo.GoodsSortAdminVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Daniel_li
 * @since 2020-12-29
 */
@RestController
@RequestMapping("/service/goods/sort")
public class GoodsSortController {

    @Autowired
    private GoodsSortService goodsSortService;

    @ApiOperation("添加商品类别")
    @PostMapping("/addGoodsSort")
    public Response addGoodsSort(@RequestBody GoodsSort goodsSort){
        boolean save = goodsSortService.save(goodsSort);
        return save? Response.ok().message("添加成功"):Response.error().message("添加失败");
    }

    @ApiOperation("根据id删除商品类别")
    @DeleteMapping("/removeSortById/{id}")
    public Response removeSortById(@PathVariable String id){
        boolean b = goodsSortService.removeById(id);
        return b? Response.ok():Response.error();
    }
    //TODO 商品类别分页查询

    @ApiOperation("获取商品类别")
    @GetMapping("/getGoodsSortList")
    public Response getGoodsSortList(){
       List<GoodsSortAdminVo> goodsSortAdminVos = goodsSortService.getGoodsSortList();
        return Response.ok().data("goodsSortList", goodsSortAdminVos);
    }

    @ApiOperation("修改商品类别")
    @PostMapping("/updateGoodsSort")
    public Response updateGoodsSort(@RequestBody GoodsSort goodsSort){
        boolean b = goodsSortService.updateById(goodsSort);
        return b? Response.ok():Response.error();
    }






}

